package com.wangsd.web.weixin.controller;


import com.wangsd.common.entity.Result;
import com.wangsd.web.weixin.entity.Follow;
import com.wangsd.web.weixin.service.FollowService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 公众号关注信息表
 * </p>
 *
 * @author generator
 * @since 2019-11-04
 */
@RestController
@RequestMapping("/api/follow")
public class FollowController {

    @Autowired
    FollowService followService;

    /**
     * 根据unionId 获取openId
     *
     * @param unionId 公共ID
     */
    @RequestMapping("/getOpenIdByUnionId")
    public Object getOpenIdByUnionId(String unionId) {
        if(StringUtils.isBlank(unionId)){
            return Result.fail("unionId 不能为空");
        }
        Follow follow = followService.selectByUnionId(unionId);
        if(follow != null && StringUtils.isNotBlank(follow.getOpenId())){
            return Result.success(follow.getOpenId());
        }else{
            return Result.fail("微信授权中，请稍后再试");
        }
    }

}

